package edu.gatech.geochat;

import edu.gatech.geochat.model.GeoMessage;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ViewNoteActivity extends BetterActivity {
	
	public static void launch(Activity source, GeoMessage message) {
		GUISpace.put(ViewNoteActivity.class, "message", message);
		Intent intent = new Intent(source, LoginActivity.class);
		source.startActivity(intent);
	}
	
	private TextView authorView, messageView, coordsView, votesView;
	
	@Override
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.note_view);
		
		authorView  = (TextView) findViewById(R.id.username);
		messageView = (TextView) findViewById(R.id.noteText);
		coordsView  = (TextView) findViewById(R.id.noteCoords);
		votesView   = (TextView) findViewById(R.id.voteCount);
	}
	
	@Override
	public void onResume() {
		super.onResume();
		
		GeoMessage msg = (GeoMessage)GUISpace.get(getClass(), "message");
		authorView.setText(msg.getUser());
		messageView.setText(msg.getText());
		coordsView.setText("(" + msg.getLocation() + ")");
		int votes = msg.getVotes();
		if (votes >= 0) {
			votesView.setText("+" + votes);
			votesView.setTextColor(0x0000FF00);
		} else {
			votesView.setText("" + votes);
			votesView.setTextColor(0x00FF0000);
		}
	}
	
	public void upvote(View view) {
		((GeoMessage)GUISpace.get(getClass(), "message")).upvote();
	}
	public void downvote(View view) {
		((GeoMessage)GUISpace.get(getClass(), "message")).downvote();
	}
}
